package com.junyi.main;


import com.junyi.child1.spi.HelloService;

import java.util.Arrays;
import java.util.Iterator;
import java.util.ServiceLoader;

public class Application {

    public static void main(String[] args)  {
        ServiceLoader<HelloService> serviceLoader = ServiceLoader.load(HelloService.class);
        Iterator<HelloService> it = serviceLoader.iterator();
        String msg = "Test SPI";
        while (it.hasNext()) {
            HelloService s = it.next();
            System.out.println(String.format("class: %s, result: %s ", s.getClass().getName(), s.f(msg)));
        }
    }

    public int[][] construct2DArray(int[] original, int m, int n) {
        if (original.length != m * n) {
            return new int[0][];
        }
        int[][] result = new int[m][n];
        for (int i = 0; i < original.length; i += n) {
            System.arraycopy(original, i, result[i / n], 0, n);
        }
        return result;
    }
}
